/**
 * @FileName: Sender03.java
 * @Package: com.rabbitmq
 * @author lig134
 * @created 2017/3/9 13:47
 * <p>
 * Copyright 2015 ziroom
 */
package com.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * <p></p>
 * 加入消息类型
 * <PRE>
 * <BR>	修改记录
 * <BR>-----------------------------------------------
 * <BR>	修改日期			修改人			修改内容
 * </PRE>
 *
 * @author lig134
 * @since 1.0
 * @version 1.0
 */
public class Sender03 {
    public static void main(String[] args) throws IOException, TimeoutException {

        ConnectionFactory connFac = new ConnectionFactory() ;

        //RabbitMQ-Server安装在本机，所以直接用127.0.0.1
        connFac.setHost("master");
        connFac.setUsername("ligen");
        connFac.setPassword("ligen");

        //创建一个连接
        Connection conn = connFac.newConnection() ;

        //创建一个渠道
        Channel channel = conn.createChannel() ;

        String exchangeName = "exchange02";

        String messageType = "type01";
        String messageType1="type02";
        String messageType2="type03";

        channel.exchangeDeclare(exchangeName, "direct") ;

        //定义Queue名
        String msg = "Hello World!";

        //发送消息
        channel.basicPublish( exchangeName , messageType , null , (msg+"1").getBytes());
        channel.basicPublish(exchangeName, messageType1, null, (msg + "2").getBytes());
        channel.basicPublish( exchangeName , messageType2 , null , (msg+"3").getBytes());

        System.out.println("send message[" + msg + "] to "+ exchangeName +" success!");

        channel.close();
        conn.close();

    }
}